import { defineStore } from 'pinia';
import api from '@/api';
// import { permission } from 'process';
export const useAdminStore = defineStore('admin', {
    //保存公共的数据
    state: () => {
        return {
            adminInfo: {
                role: {
                    permissions: []
                }
            },
        }
    },


    //保存公共的计算属性
    getters: {
        menusdata: (state) => {
            if (state.adminInfo.role) {
                return state.adminInfo.role.permissions;
            }
            return [];
        }
    },



    //保存公共的方法
    actions: {
        async getAdminInfoAsync() {
            const res = await api.admins.getInfo();
            // console.log(res);
            if (res.code == 200) {
                this.adminInfo = res.data;
                //将请求结果返回出去
                return res.data.role.permissions;
            }
        },
        logout(){
            //将管理员信息重置为初始值
            this.adminInfo={
                role:{
                    permissions:[]
                }
            }
            //删除本地存储中的token
            localStorage.removeItem('user_token');
        }


    }


});
